﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
using Paathshala.Kernel;

namespace Paathshala.Kernel
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private ConsoleWriter _consoleWriter;
        private Thread _serverThread;

        public delegate void AddServerLog(string log, LogType type);

        public event AddServerLog AddServerLogHandler;
        

        private enum ServerState
        {
            Stopped,
            Starting,
            Stopping,
            Started,
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void StartServer()
        {
            Console.WriteLine(@"Server is starting...",LogType.Error);
            Console.WriteLine(@"Server Started...");
            Console.WriteLine(@"Ready...");
            Console.WriteLine(@"Ready...");
            Console.WriteLine(@"Ready...");
            Console.WriteLine(@"Ready...");
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _consoleWriter = new ConsoleWriter(MsgConsole);
            bool silent = Environment.GetCommandLineArgs().Contains("silent");
            if (!silent)
            {
                Console.SetOut(_consoleWriter);
            }
            
            _serverThread = new Thread(StartServer);
            _serverThread.Start();
        }
    }
}
